//
//  RegisterViewController.m
//  SaltLightDemo
//
//  Created by lzy on 2018/5/9.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "RegisterViewController.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "DetailsOfArticleViewController.h"
#import "MGRequestService+My.h"
@interface RegisterViewController ()
@property (nonatomic , strong) UITextField *yhmTF;
@property (nonatomic , strong) UITextField *mmTF;
@property (nonatomic , strong) UITextField *cfmmTF;
@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.fd_prefersNavigationBarHidden = YES;
    [self initUI];
    // Do any additional setup after loading the view.
}
-(void)initUI{
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH*260.0/375)];
    image.image = [UIImage imageNamed:@"icon_img_bj1"];
    image.userInteractionEnabled = YES;
    [self.view addSubview:image];
    
    UIImageView * image1 = [[UIImageView alloc]init];
    image1.frame = CGRectMake((SCREEN_WIDTH-SCREEN_WIDTH*95.0/375.0)/2, image.frame.size.height*102.5/260, SCREEN_WIDTH*95.0/375.0, SCREEN_WIDTH*95.0/375.0);
    image1.layer.masksToBounds = YES;
    image1.layer.cornerRadius = SCREEN_WIDTH*95.0/375.0/2;
    image1.layer.borderColor = [UIColor whiteColor].CGColor;
    image1.layer.borderWidth = 6.0;
    image1.image = [UIImage imageNamed:@"icon"];
    [image addSubview:image1];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    button.frame = CGRectMake(10, 20, 50, 44);
    [button addTarget:self action:@selector(goBackClick) forControlEvents:UIControlEventTouchUpInside];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [button setTitle:@"" forState:UIControlStateNormal];
    [image addSubview:button];
    
    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(80, 20, SCREEN_WIDTH-160, 44)];
    label1.font = [UIFont boldSystemFontOfSize:14.0];
    label1.text = @"注册";
    label1.textColor = [UIColor add_colorWithRGBHexString:@"333333"];
    label1.textAlignment = NSTextAlignmentCenter;
    [image addSubview:label1];
    
    UIImageView * image2 = [[UIImageView alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(image.frame)+75, 25, 25)];
    image2.image = [UIImage imageNamed:@"app_icon_sj"];
    [self.view addSubview:image2];
    
    UITextField *yhmTF = [[UITextField alloc] initWithFrame:CGRectMake(90, CGRectGetMaxY(image.frame)+75, self.view.frame.size.width-145, 25)];
    self.yhmTF = yhmTF;
    self.yhmTF.font = [UIFont systemFontOfSize:14.0];
    //    self.ysmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.yhmTF.tag = 1;
    self.yhmTF.textAlignment = NSTextAlignmentLeft;
    self.yhmTF.returnKeyType = UIReturnKeyDone;
    self.yhmTF.placeholder = @"请输入用户名";
    self.yhmTF.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:self.yhmTF];
    
    UIView * line1 = [[UIView alloc]initWithFrame:CGRectMake(0, 25, yhmTF.frame.size.width, 1.0)];
    line1.backgroundColor = [UIColor add_colorWithRGBHexString:@"EFEFF4"];
    [yhmTF addSubview:line1];
    
    UIImageView * image3 = [[UIImageView alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(image2.frame)+40, 25, 25)];
    image3.image = [UIImage imageNamed:@"mima"];
    [self.view addSubview:image3];
    
    UITextField *mmTF = [[UITextField alloc] initWithFrame:CGRectMake(90, CGRectGetMaxY(image2.frame)+40, self.view.frame.size.width-145, 25)];
    self.mmTF = mmTF;
    self.mmTF.font = [UIFont systemFontOfSize:14.0];
    //    self.ysmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.mmTF.tag = 1;
    self.mmTF.textAlignment = NSTextAlignmentLeft;
    self.mmTF.returnKeyType = UIReturnKeyDone;
    self.mmTF.placeholder = @"请输入密码";
    self.mmTF.secureTextEntry = YES;
    self.mmTF.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:self.mmTF];
    
    UIView * line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 25, mmTF.frame.size.width, 1.0)];
    line2.backgroundColor = [UIColor add_colorWithRGBHexString:@"EFEFF4"];
    [mmTF addSubview:line2];
    
    UIImageView * image4 = [[UIImageView alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(image3.frame)+40, 25, 25)];
    image4.image = [UIImage imageNamed:@"mima"];
    [self.view addSubview:image4];
    
    UITextField *cfmmTF = [[UITextField alloc] initWithFrame:CGRectMake(90, CGRectGetMaxY(image3.frame)+40, self.view.frame.size.width-145, 25)];
    self.cfmmTF = cfmmTF;
    self.cfmmTF.font = [UIFont systemFontOfSize:14.0];
    //    self.ysmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.cfmmTF.tag = 1;
    self.cfmmTF.textAlignment = NSTextAlignmentLeft;
    self.cfmmTF.returnKeyType = UIReturnKeyDone;
    self.cfmmTF.placeholder = @"请在次输入密码";
    self.cfmmTF.secureTextEntry = YES;
    self.cfmmTF.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:self.cfmmTF];
    
    UIView * line3 = [[UIView alloc]initWithFrame:CGRectMake(0, 25, cfmmTF.frame.size.width, 1.0)];
    line3.backgroundColor = [UIColor add_colorWithRGBHexString:@"EFEFF4"];
    [cfmmTF addSubview:line3];
    
    UIButton * button12 = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 250)/2.0, CGRectGetMaxY(cfmmTF.frame)+20, 250, 40)];
    [button12 setTitle:@"《用户服务协议》" forState:UIControlStateNormal];
    button12.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [button12 setTitleColor:[UIColor add_colorWithRGBHexString:@"2196F3"] forState:UIControlStateNormal];
    [button12 addTarget:self action:@selector(agreement:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button12];
    
    UIButton * button11 = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 250)/2.0, CGRectGetMaxY(button12.frame)+5, 250, 40)];
    button11.backgroundColor = [UIColor add_colorWithRGBHexString:@"FFD600"];
    [button11 setTitle:@"注册" forState:UIControlStateNormal];
    button11.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [button11 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button11 addTarget:self action:@selector(register:) forControlEvents:UIControlEventTouchUpInside];
    button11.layer.masksToBounds = YES;
    button11.layer.cornerRadius = 20;
    [self.view addSubview:button11];
    
    
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
    
}
-(void)agreement:(UIButton *)btn{
//    [self showToastInViewController:@"协议"];
    DetailsOfArticleViewController * ctr = [[DetailsOfArticleViewController alloc]init];
    ctr.url = @"https://games.jingjibang.cn:4430/yuebing/testapp/instructions.html";
    [self.navigationController pushViewController:ctr animated:YES];
}
-(void)register:(UIButton *)btn{
    if ([self.mmTF.text isEqualToString:self.cfmmTF.text]) {
        [MGRequestService requestRegisterWithuserName:self.yhmTF.text AndPassword:self.cfmmTF.text success:^(MGBaseRspModel *model) {
            if (model.resultCode == 0) {
               
                [self showToastInViewController:@"注册成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                [self showToastInViewController:model.errorMessage];
            }
            
        } failure:^(NSError *error) {
            [self showToastInViewController:@"注册失败"];
        }];
    }else
    {
        [self showToastInViewController:@"重复密码与首次输入密码不一样"];
    }
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
